<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<a href="http://www.baidu.com">百度</a>
<a href="http://www.baidu.com">百度</a>
<a href="http://www.baidu.com">百度</a>
<a href="http://www.baidu.com">百度</a>
<a href="http://www.baidu.com">百度</a>
<a href="http://www.baidu.com">百度</a>
<a href="https://www.baidu.com">百度</a>
<a href="http://www.baidu.com">百度</a>
<a href="http://www.baidu.com">百度</a>
<a href="http://www.baidu.com">百度</a>
<a href="https://www.baidu.com">百度</a>
<div></div>


</body>
</html>
<script>
    Function.prototype.before = function( beforefn ){
        var __self = this;

        return function(){ // 返回包含了原函数和新函数的"代理"函数
            console.log(this)
            // before
            beforefn.apply( this, arguments ); // 执行新函数，修正 this
            console.log(__self)
            return __self.apply( this, arguments ); // 执行原函数
        }
    };
    Function.prototype.after = function( afterfn ){
        var __self = this;

        return function(){
            console.log(this)
            // after
            var ret = __self.apply( this, arguments );
            afterfn.apply( this, arguments );
            return ret;
        }
    };
    Function.prototype.before1 = function( beforefn ){
        var __self = this;

        return function(){ // 返回包含了原函数和新函数的"代理"函数
            console.log(this)
            // before1
            beforefn.apply( this, arguments ); // 执行新函数，修正 this
            return __self.apply( this, arguments ); // 执行原函数
        }
    };
    Function.prototype.after1 = function( afterfn ){
        var __self = this;

        return function(){
            console.log(this)
            // after1
            var ret = __self.apply( this, arguments );
            afterfn.apply( this, arguments );
            return ret;
        }
    };
    var func = function(){
        console.log( 2 );
    };
    func = func.after1(function(){
        console.log(4)
    }).before(function(){
        console.log( 1 );
    }).before1(function(){
        console.log('before1')
    }).after(function(){
        console.log( 3 );
    });
    func();
    var cost = (function(){
        var args = [];
        return function(){
            if ( arguments.length === 0 ){
                var money = 0;
                for ( var i = 0, l = args.length; i < l; i++ ){
                    money += args[ i ];
                }
                return money;
            }else{
                [].push.apply( args, arguments );
            }
        }
    })();
</script>